import torch

# Uniform Symmetric Quantizer (线性对称量化)
def usq_int8(t):
    scale = torch.max(
                torch.abs(torch.max(t)),
                torch.abs(torch.min(t))) / 127.
    t_q = (t / scale).int()
    return scale, t_q

# Uniform Symmetric Quantizer (线性对称量化)
# 指定scale
def usq_int8_with_scale(t, scale=1.):
    t_q = (t / scale).int()
    return t_q